﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Activation;
using System.Reflection;
using System.Web.Routing;

namespace _180FrameWork.Common.WCFHelper
{
    public static class ServiceRegister 
    {
        private static ServiceHostFactory wshf;

        static ServiceRegister()
        {
            wshf = new MyServiceHostFactory();
        }

        public static void RegisterAllService(string CustomAssemblyPath)
        {
            Assembly[] list = BaseServiceRegister.GetDynamicAssemblyList(CustomAssemblyPath);
            RegisterAllService(list);
        }

        public static void RegisterAllService(Assembly[] list)
        {
            foreach (var ass in list)
            {
                var ts = ass.GetTypes();
                foreach (var t in ts)
                {
                    if (t.Name.EndsWith("Service") && t.IsClass)
                    {
                        var serviceName = t.Name;
                        serviceName = serviceName.Replace(".", "_");
                        var sr = new ServiceRoute(serviceName, wshf, t);
                        
                        RouteTable.Routes.Add(sr);
                    }
                }
            }
        }
    
    }
}
